<?php
session_start();
include("common/connect.php");
include("common/common.php");

if( !isset($_SESSION["user"]) ) 
{
	$url = "Location:login.php?ref=integral.php";
	header($url);
}

$showtype = CheckUrlParamNoDie("showtype");
$tag = CheckUrlParamNoDie("tag");
$gid = CheckUrlParamNoDie("gid");
$name = CheckUrlParamNoDie("name");

if(isset($_POST["submit"]))
{
	$inIevel = trim(GetPostParamStr("inIevel"));
	$inTubi = trim(GetPostParamStr("inTubi"));
	$content = trim(GetPostParamStr("content"));
	
	if($inIevel != "" || $inTubi != "")
	{
		$sql="select level, tubi from user where id=$gid";
   		$result=mysql_query($sql);
		if(mysql_num_rows($result) > 0)
		{
			$row = mysql_fetch_assoc( $result );
			$Ievel = $row["level"]+$inIevel;
			$Tubi = $row["tubi"]+$inTubi;
			
			//echo $Ievel.'bbbbbb'.$Tubi;
			
			$sql="update user set level='$Ievel', tubi='$Tubi' where id=$gid";
			mysql_query($sql);
		}
	}
	if($content != "")
	{
		$sql = "insert into gwt_msg (content,touser) values ('$content', $gid)";
		mysql_query( $sql );
	}
	echo "<script>window.history.go(-2);</script>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>购物兔积分管理</title>
<style type="text/css">
body {font-size: 12px;color: #000;font-family: 宋体;}
.STYLE1 {font-size: 13px;font-weight: bold;}
table {border-collapse:collapse; border-spacing:2px;  font-size:12px;}
td,th { display:table-cell; vertical-align:inherit;}
img { border:0; vertical-align:top;}
</style>
<script language="javascript">
function OnFind()
{
	var site_tag = document.getElementById("Site_Tag").value;
	var input_tradeid = document.getElementById("showtype").value;
	window.location.href= "integral.php?showtype=" + input_tradeid + "&tag=" + site_tag ;
}
function ontIevel()
{
	var inIevel = document.getElementById("inIevel").value;
	var inTubi = document.getElementById("inTubi").value;
	var content = document.getElementById("content").value;
	
	if (inIevel == "" && inTubi == "")
	{
		alert("请确认你要添加的积分或者兔币输入正确~~~~");
     	return false;
     }
	 if (content == "")
	{
		alert("请确认添加积分的原由，这是给用户看的~~");
     	return false;
     }
	 
	return true;
}
</script>
</head>
<body>
<div style="width:920px; margin:0 auto; position:relative;">
<table width="920" border="1" cellpadding="0" cellspacing="0" align="center" bordercolor="#a8a8a8">
	<tr>
    	<td height="40" align="center" colspan="6"><font size="+2">购物兔积分管理</font></td>    
    </tr>
    <tr>
    	<td height="30" colspan="6">&nbsp;&nbsp;&nbsp;&nbsp;
        	<select  class="tedinp" name="Site_Tag" id="Site_Tag" size="1">
          		<option value="1" selected='selected'>序列号</option>
          		<option value="2">支付宝</option>
          		<option value="3">手机号</option>
        	</select>&nbsp;&nbsp;
        	<input type="text" size="20" id="showtype" name="showtype" value="">&nbsp;&nbsp;
            <input type="button" value="查找" onclick="javascript:OnFind();">&nbsp;&nbsp;<a href="integral.php">默认显示</a>
     	</td>
    </tr>
    <tr align="center" bgcolor="#66CCFF">
    	<td  width="60" height="30" title="序列号也就是所谓的邀请码">序列号</td>
        <td>支付宝账号</td>
        <td width="170">手机号码</td>
        <td width="100">积分</td>
        <td width="100">兔币</td>
        <td width="100">操作</td>
    </tr>
<?php
$sql="";
//$limit = " limit ". $nPage*20 .",20";
$sql = "";
if($showtype != "" && $tag == "1")
	$sql .= " where id=$showtype";
if($showtype != "" && $tag == "2")
	$sql .= " where tb_id='$showtype'";
if($showtype != "" && $tag == "3")
	$sql .= " where phone=$showtype";

$sql = "select * from user".$sql." order by id asc limit 10";
$result = mysql_query( $sql );
while( $result && $row = mysql_fetch_assoc( $result ))
{
?>
    <tr align="center" <?php if($gid == $row["id"] ) echo 'bgcolor="#FF6699"'; ?>>
    	<td height="30"><?php echo $row["id"]; ?></td>
        <td><?php echo $row["tb_id"]; ?></td>
        <td><?php echo $row["phone"]; ?></td>
        <td><?php echo $row["level"]; ?></td>
        <td><?php echo $row["tubi"]; ?></td>
        <td><a href="?gid=<?php echo $row["id"]; ?>&name=<?php echo $row["tb_id"]; ?>&showtype=<?php echo $showtype; ?>&tag=<?php echo $tag; ?>">添加</a></td>
    </tr>
<?php } ?>
</table>
	<?php if($gid != ""){ ?>
    <div style="position:absolute; background:#39F; width:520px; left:200px; top:150px;">
        <div style=" margin:20px; background:#6CF;">
        <form action="" method="post" onsubmit="return ontIevel();">
            <p><span style="width:400px; display:inline-block; padding-left:30px;"><b><?php echo $name; ?></b></span><a href="integral.php">关闭</a></p>
            <p style="padding:10px 0 0 30px">积分：<input type="text" size="20" id="inIevel" style="width:40px;" name="inIevel" value="">&nbsp;&nbsp;兔币：<input type="text" size="20" style="width:40px;" id="inTubi" name="inTubi" value="">&nbsp;&nbsp;<font color="#FF0000">加多少积分就输入多少！下面消息发送给兔丝</font></p>
            <p style="padding:10px 0 0 30px">消息：<textarea position="0" style="width:350px;" length="140" id="content" name="content"></textarea></p>
            <p style=" width:50px; margin:0 auto; padding-bottom:10px;"><input type="submit" name="submit" value="确 认" style=" width:80px;" /></p>
        </form>
        </div>
    </div>
    <?php } ?>
</div>
</body>
</html>
